import 'reflect-metadata'
import express from 'express'

import { dataSource } from './db/datasource'
import router from './controller'

import dotenv from 'dotenv'

console.log('当前环境', process.env.NODE_ENV)

dotenv.config({
  path: ['.env', '.env.' + process.env.NODE_ENV]
})

const app = express()

// 数据库初始化
dataSource
  .initialize()
  .then(() => {
    app.use('/api', router)

    app.listen(process.env.PORT, () => {
      console.log('服务启动, http://localhost:' + process.env.PORT)
    })
  })
  .catch((e) => {
    console.log('数据库启动失败')
    console.log(e)
  })
